package com.eims.ball.info.adapter;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.contans.view.PeilvOupeiVo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import bls.juejin.cn.R;

public class PeilvOupeiListAdapter extends BaseAdapter {
	private Context context;
	
	private ArrayList<PeilvOupeiVo> peilvOupeiVos;

	public PeilvOupeiListAdapter(Context context,ArrayList<PeilvOupeiVo> peilvOupeiVos) {
		super();
		this.context = context;
		this.peilvOupeiVos=peilvOupeiVos;

	}

	@Override
	public int getCount() {
		if (peilvOupeiVos!=null) {
			return peilvOupeiVos.size();
		}

		return 0;
	}

	@Override
	public Object getItem(int position) {

		return position;
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		ViewHolder holder;
		// 判断View是否为空
		if (view == null) {
			holder = new ViewHolder();

			view = LayoutInflater.from(context).inflate(R.layout.peilv_oupei_list_adapter_item, null);
			
			
			holder.tv_name=(TextView) view.findViewById(R.id.tv_name);
			holder.tv_chu_main=(TextView) view.findViewById(R.id.tv_chu_main);
			holder.tv_chu_flat=(TextView) view.findViewById(R.id.tv_chu_flat);
			holder.tv_chu_gues=(TextView) view.findViewById(R.id.tv_chu_gues);
			holder.tv_chu_return=(TextView) view.findViewById(R.id.tv_chu_return);
			holder.tv_time=(TextView) view.findViewById(R.id.tv_time);
			holder.tv_ji_main=(TextView) view.findViewById(R.id.tv_ji_main);
			holder.tv_ji_flat=(TextView) view.findViewById(R.id.tv_ji_flat);
			holder.tv_ji_gues=(TextView) view.findViewById(R.id.tv_ji_gues);
			holder.tv_ji_return=(TextView) view.findViewById(R.id.tv_ji_return);
			
			
			
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}

		holder.tv_name.setText(peilvOupeiVos.get(position).getCompany());
		holder.tv_chu_main.setText(peilvOupeiVos.get(position).getNew__p1());
		holder.tv_chu_flat.setText(peilvOupeiVos.get(position).getNew__p2());
		holder.tv_chu_gues.setText(peilvOupeiVos.get(position).getNew__p3());
		holder.tv_chu_return.setText(peilvOupeiVos.get(position).getReturn__rate()+"%");
		
		holder.tv_time.setText(peilvOupeiVos.get(position).getTimestr());
		holder.tv_ji_main.setText(peilvOupeiVos.get(position).getOld__p1());
		holder.tv_ji_flat.setText(peilvOupeiVos.get(position).getOld__p2());
		holder.tv_ji_gues.setText(peilvOupeiVos.get(position).getOld__p3());
		holder.tv_ji_return.setText(peilvOupeiVos.get(position).getOld_return_rate()+"%");
		
		
	
		

		
		return view;
	}

	public boolean isMobileNO(String mobiles) {
		Pattern p = Pattern.compile("1[0-9]{10}");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}

	static class ViewHolder {
		
		TextView tv_name,tv_chu_main,tv_chu_flat,tv_chu_gues,tv_chu_return,tv_time,tv_ji_main,tv_ji_flat,tv_ji_gues,tv_ji_return;

	}

	public String formateRate(String rateStr) {
		if (rateStr.indexOf(".") != -1) {

			int num = 0;
			num = rateStr.indexOf(".");

			String dianAfter = rateStr.substring(0, num + 1);
			String afterData = rateStr.replace(dianAfter, "");
			if (afterData.length() < 2) {
				afterData = afterData + "0";
			} else {
				afterData = afterData;
			}
			return rateStr.substring(0, num) + "." + afterData.substring(0, 2);
		} else {
			if (rateStr == "1") {
				return "100";
			} else {
				return rateStr;
			}
		}
	}

}
